package com.readfeed.app.data;

import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class FeedsTable {
	
	public static final String TABLE_ITEMS_NAME = "items";
	public static final String COLUMN_ID = "_id";
	public static final String COLUMN_TITLE = "title";
	public static final String COLUMN_URI = "link";
	public static final String COLUMN_GUID = "guid";
	public static final String COLUMN_PUBDATE = "pub_date";
	public static final String COLUMN_SUMMARY = "summary";
	public static final String COLUMN_CHANNEL_ID = "channel_id";
	
	private static final String DATABASE_CREATE = "create table "
			+ TABLE_ITEMS_NAME
			+ "("
			+ COLUMN_ID + " integer primary key autoincrement, "
			+ COLUMN_TITLE + " text not null, "
			+ COLUMN_URI + " text not null, "
			+ COLUMN_GUID + " text not null, "
			+ COLUMN_PUBDATE + " integer not null, "
			+ COLUMN_SUMMARY + " text, "
			+ COLUMN_CHANNEL_ID + " integer references "
			+ ChannelsTable.TABLE_CHANNELS_NAME 
			+ "(" + ChannelsTable.COLUMN_ID + ") not null"
			+ ");";
	
	public static void onCreate(SQLiteDatabase database){
		database.execSQL(DATABASE_CREATE);		
	}
	
	public static void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion){
		Log.w(ChannelsTable.class.getName(), "Upgrading database from version "
		        + oldVersion + " to " + newVersion);
		    database.execSQL("DROP TABLE IF EXISTS " + TABLE_ITEMS_NAME);
		    onCreate(database);
	}
}
